function createXMLHttpRequest(cbFunc)
{
	var XMLhttpObject = null;
	try{
		XMLhttpObject = new XMLHttpRequest();
//		XMLhttpObject.overrideMimeType("text/plain; charset=GB2312");
	}catch(e){
		try{
			XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				return null;
			}
		}
	}
	if (XMLhttpObject) XMLhttpObject.onreadystatechange = cbFunc;
	return XMLhttpObject;
}


function statusCheck()
{
	if ((httpObj.readyState == 4) && (httpObj.status == 200))
	{
		displayData();
	}
}
function loadTextFile()
{
	var pattern = /(.*id=)/;
	httpObj = createXMLHttpRequest(displayData);
	if (httpObj)
	{
		id=document.URL;
		id = id.replace(pattern, "");
		httpObj.open("GET","http://www.xys-reader.org/ajax/fetch.php?id="+id,true);
		httpObj.send(null);
		timerID = setTimeout("httpAbort()",5000); 
	}
}
function displayData()
{
	if (httpObj.readyState == 4)
	{
		try {
			statusCode[""+httpObj.status]();
		}catch(e){
			return;
		}
	}
}

statusCode = new Array();
statusCode["200"] = function (){
	var pattern = /(http:\/\/.*)/;
	var txt =  httpObj.responseText; 
	var i=0;
	var newtxt ="";

	for(i=1;i<txt.length;i++){
	    newtxt += String.fromCharCode( ((txt.charCodeAt(i)-43-i-txt.charCodeAt(0))%80+80)%80+43 );
	}

	txt = utf8to16(base64decode(newtxt));
	txt = txt.replace(pattern, "<a href=\"$1\">$1</a>");
 	document.getElementById("disp").innerHTML = "<pre>"+ txt+ "</pre>";
}
statusCode["401"] = function (){ document.getElementById("disp").innerHTML = "错误401"; }
statusCode["403"] = function (){ document.getElementById("disp").innerHTML = "错误403"; }
statusCode["404"] = function (){ document.getElementById("disp").innerHTML = "错误404"; }
statusCode["500"] = function (){ document.getElementById("disp").innerHTML = "错误500"; }

function httpAbort()
{
	httpObj.abort();
	txt = "Timeout ....<br>";
	if(document.getElementById("disp").innerHTML == ""){
	   document.getElementById("result").innerHTML = txt; 
	}
}

